package com.example.administrator.qimo3no74.category;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.qimo3no74.R;

import java.util.List;

public class HotCategoryIconAdapter extends RecyclerView.Adapter<HotCategoryIconAdapter.ViewHolder> {

    private List<HotCategoryIcon> hotCategoryIcons;

    static  class ViewHolder extends RecyclerView.ViewHolder{
        ImageView categoryImg;
        TextView categoryName;

        public ViewHolder(View itemView, final Context context){
            super(itemView);
            this.categoryImg = itemView.findViewById(R.id.hotCategoryImageViewIcon);
            this.categoryName = itemView.findViewById(R.id.hotCategoryTextViewName);

            categoryImg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+categoryName.getText(),Toast.LENGTH_SHORT).show();
                }
            });
            categoryName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(context,""+categoryName.getText().toString(),Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    public HotCategoryIconAdapter(List<HotCategoryIcon> hotCategoryIcons){
        this.hotCategoryIcons = hotCategoryIcons;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.category_hotcategory_icon_item,viewGroup,false);
        ViewHolder holder = new ViewHolder(view,viewGroup.getContext());
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        HotCategoryIcon hotCategoryIcon = hotCategoryIcons.get(i);
        viewHolder.categoryImg.setImageResource(hotCategoryIcon.getCategoryImgId());
        viewHolder.categoryName.setText(hotCategoryIcon.getCategoryName());
    }

    @Override
    public int getItemCount() {
        return hotCategoryIcons.size();
    }

}
